<?php
require_once(APP_OBJ_PATH . 'model.class.php');

/**
 * Gebruiker
 *
 * @package scorpion-magenta
 * @author Nicky van Meurs
 * @copyright 2012
 * @version 1.0
 * @access public
 */
class Gebruiker extends Model
{
	protected $GebruikerID;
	protected $Email;
	protected $Wachtwoord;
	protected $GroepID;
	protected $BedrijfID;
	protected $Budget;
	protected $Voornaam;
	protected $Tussenvoegsel;
	protected $Achternaam;
	protected $Straat;
	protected $Huisnummer;
	protected $HuisnummerToevoeging;
	protected $Postcode;
	protected $Woonplaats;
	protected $Telefoon;
	protected $Personeelsnummer;
	protected $Aanmaker;
	protected $BetaalMethode;
	protected $PuntenKoers;

	public static function getByEmail($email)
	{
		global $db;
		$stmt = $db->prepare(self::getSelect() . " WHERE Email = :email LIMIT 1");
		$stmt->bindParam(':email', $email, PDO::PARAM_STR);
		$stmt->execute();
		$gebruiker = $stmt->fetch(PDO::FETCH_ASSOC);
		return ($gebruiker['GebruikerID'] !== null) ? new static($gebruiker) : false;
	}

	public static function getByEmailAndPass($email, $pass)
	{
		global $db;
		$stmt = $db->prepare(self::getSelect() . " WHERE Email = :email AND Wachtwoord = :pass LIMIT 1");
		$stmt->bindParam(':email', $email, PDO::PARAM_STR);
		$stmt->bindParam(':pass', $pass, PDO::PARAM_STR);
		$stmt->execute();
		$gebruiker = $stmt->fetch(PDO::FETCH_ASSOC);
		return ($gebruiker['GebruikerID'] !== null) ? new static($gebruiker) : false;
	}

	public static function emailAlreadyExists($email)
	{
		global $db;
		$stmt = $db->prepare(self::getSelect() . " WHERE Email = :email LIMIT 1");
		$stmt->bindParam(':email', $email, PDO::PARAM_INT);
		$stmt->execute();
		return ($stmt->fetch(PDO::FETCH_ASSOC)) ? true : false;
	}
}
?>
